package com.gukun.springboot.tdengine.util;

import java.sql.Timestamp;

public class TypeUtils {
    public static <T> T convertStringToType(String value, Class<T> clazz) {
        if (clazz == String.class) {
            return clazz.cast(value);
        }else if (clazz == Integer.class) {
            return clazz.cast(Integer.parseInt(value));
        }else if (clazz == Long.class) {
            return clazz.cast(Long.parseLong(value));
        }else if (clazz == Double.class) {
            return clazz.cast(Double.parseDouble(value));
        }else if (clazz == Float.class) {
            return clazz.cast(Float.parseFloat(value));
        }else if (clazz == Boolean.class) {
            return clazz.cast(Boolean.parseBoolean(value));
        }else if (clazz == Byte.class) {
            return clazz.cast(Byte.parseByte(value));
        }else if(clazz == Short.class) {
            return clazz.cast(Short.parseShort(value));
        }else if(clazz == Timestamp.class){
            return clazz.cast(Timestamp.valueOf(value));
        }else{
            return null;
        }
    }
}
